/*
 * Copyright 2009 (c) Patrick Pietens
 *
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use,
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following
 * conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 */
package indigo.utils
{
	import flash.external.ExternalInterface;
	import flash.net.URLRequest;
	import flash.net.navigateToURL;
	
	
	
	
	/**
	 * The getURL is used to navigate to an URL. This method uses the javascript "window.open" function to bypass
	 * IE8.0's popupblocker when using navigateToURL. In order to open the links correctly, you need to make sure 
	 * that the parameter AllowScriptAccess is set to "always":<br/><br/>
	 * <param name="AllowScriptAccess" value="always"><br/><br/>
	 * Thanks to Paul Tondeur for providing this script.<br/><br/>
	 * 
	 * @param String that indicates the URL to navigate to
	 * @param String that indicates the window in which the URL is opened
	 * @see http://www.paultondeur.com/2009/01/18/as3-clicktag-case-and-popup-blocker-fix/ 
	 * 
	 * @playerversion Flash 9
	 * @langversion ActionScript 3.0 
	 */
	public function getURL( url:String, window:String = "_blank" ):void
	{
		var myRequest:URLRequest = new URLRequest( url );
		if(!ExternalInterface.available)
		{
			navigateToURL( myRequest, window );
		}
		else
		{
			var strUserAgent:String = String( ExternalInterface.call( "function() { return navigator.userAgent; }" ) ).toLowerCase( );
				
			if(strUserAgent.indexOf( "firefox" ) != -1 || (strUserAgent.indexOf( "msie" ) != -1 && uint( strUserAgent.substr( strUserAgent.indexOf( "msie" ) + 5, 3 ) ) >= 7))
			{
				ExternalInterface.call( "window.open", myRequest.url, window );
			}
			else
			{
				navigateToURL( myRequest, window );
			}
		}
	}
}
